package o;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnKeyListener;
import android.view.KeyEvent;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.listener.IServerCallBack;
import o.cwj.i;

public class cws implements IServerCallBack {
    private boolean ˊ = false;
    private Context ˋ;
    private djl ॱ;

    class a implements OnKeyListener {
        final /* synthetic */ cws ˎ;

        private a(cws o_cws) {
            this.ˎ = o_cws;
        }

        public boolean onKey(DialogInterface dialogInterface, int i, KeyEvent keyEvent) {
            if (4 == i && keyEvent.getAction() == 1) {
                this.ˎ.ˊ = true;
                this.ˎ.ˏ();
                ((Activity) this.ˎ.ˋ).finish();
            }
            return false;
        }
    }

    public cws(Context context) {
        this.ˋ = context;
        this.ॱ = new djl(context);
        this.ॱ.setCanceledOnTouchOutside(false);
        this.ॱ.ˋ(context.getString(i.ˋᐝ));
        this.ॱ.setOnKeyListener(new a());
        this.ॱ.show();
    }

    public void prePostResult(BaseRequest o_cvu, ResponseBean responseBean) {
    }

    public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
        if (this.ˋ instanceof Activity) {
            ˏ();
            if (Logger.ˎ()) {
                cwr.ॱ.ˎ("ShareReportCallBack", "responseCode: " + responseBean.getResponseCode() + " rtnCode: " + responseBean.getRtnCode_());
            }
            int ॱ = ॱ(responseBean);
            if (responseBean.getResponseCode() == 0 && responseBean.getRtnCode_() == 0) {
                cxr.ˏ(0);
            } else if (!this.ˊ) {
                if (3 == ॱ) {
                    evk.ˏ(this.ˋ, i.ʻ, 0).ˋ();
                } else if (ResponseBean.SERVER_DELAY_RETRY == ॱ) {
                    cwr.ॱ.ˋ("ShareReportCallBack", "store access control");
                } else {
                    evk.ˏ(this.ˋ, i.ʽ, 0).ˋ();
                }
            } else {
                return;
            }
            ((Activity) this.ˋ).finish();
            return;
        }
        cwr.ॱ.ˊ("ShareReportCallBack", "context is not an activity.");
    }

    private int ॱ(ResponseBean responseBean) {
        int responseCode = responseBean.getResponseCode();
        if (responseCode != 0 || responseBean.getRtnCode_() == 0) {
            return responseCode;
        }
        return 1;
    }

    public void ˏ() {
        if (this.ॱ != null) {
            this.ॱ.cancel();
            this.ॱ = null;
        }
    }

    public djl ˊ() {
        return this.ॱ;
    }
}
